package com.example.administrator.yuejian_2.fragment;


<<<<<<< HEAD
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
=======
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.RadioGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.ClubSearchActivity;

>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubFragment extends Fragment {

<<<<<<< HEAD
=======
    private RadioGroup radioGroup;
    private ClubPopularFragment clubPopularFragment;
    private ClubRecentFragment clubRecentFragment;

    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;
    private ImageButton search_button;

>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

    public ClubFragment() {
        // Required empty public constructor
    }

<<<<<<< HEAD

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club, container, false);
    }

=======
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        //在Fragment中添加Fragment时，调用getChildFragmentManager获取FragmentManager
        fragmentManager = getChildFragmentManager();
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club, container, false);

    }
    public void onViewCreated(View view, @Nullable Bundle saveInstanceState){
       search_button = view.findViewById(R.id.search_button);
       search_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Intent intent = new Intent();
                intent.setClass(getActivity(), ClubSearchActivity.class);
               startActivity(intent);
         }
      });

        radioGroup = view.findViewById(R.id.radioGroup_club);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.popular:
                        clubPopularFragment = new ClubPopularFragment();
                        replaceFragment(clubPopularFragment);
                        break;
                    case R.id.recent:
                        clubRecentFragment = new ClubRecentFragment();
                        replaceFragment(clubRecentFragment);
                        break;


                }
            }
        });
        radioGroup.check(R.id.popular);

    }

    private void replaceFragment(Fragment fragment){

        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder_club,fragment);
        fragmentTransaction.commit();

    }
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
}
